

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MatcherHelper {
    private List<String> re=new ArrayList<String>();
    private List<String> lis=new ArrayList<String>();
    private static int i=0; 

    public MatcherHelper(){
    }
    //读取记录的分页文件
    public void readFile(){
        String filepath="./data/index/index_"+(i++)+".txt";
        lis.clear();
        try{
            File txt=new File(filepath);
            BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(txt),"utf-8"));
            String line="";
            while((line=br.readLine())!=null){
                String[] strarray=line.split("\\s+",2);
                lis.add(strarray[1]);
            }
            br.close();
        }catch(IOException e){
            e.printStackTrace();
        }
    }
    //做正则匹配
    public List<String> matcherHelper(List<String> s){
        String regex="";
        Iterator<String> it=s.iterator();
        while(it.hasNext()){
            regex+="(?=.*"+it.next()+")";
        }
        regex+="^.*$";
        Pattern pattern=Pattern.compile(regex);
        for(int j=0;j<219;j++){
            readFile();
            it=lis.iterator(); 
            while(it.hasNext()){
            String title=it.next();
            Matcher matcher=pattern.matcher(title);
            if(matcher.find()){
                re.add(title);
                }
            }
        }
        
        if(re==null){
            return null;
        }
        else return re;
    }
}